using Net35.Xrm.Sdk.Query;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Net35.Xrm.Sdk.Linq
{
	internal static class LinkEntityExtensions
	{
		public static LinkEntity Find(this LinkEntity link, Predicate<LinkEntity> match)
		{
			if (!match(link))
			{
				return (
					from child in link.LinkEntities
					select child.Find(match)).FirstOrDefault((LinkEntity result) => result != null);
			}
			return link;
		}
		public static IEnumerable<LinkEntity> GetSubtree(this LinkEntity link)
		{
			yield return link;
			foreach (LinkEntity current in link.LinkEntities.SelectMany(new Func<LinkEntity, IEnumerable<LinkEntity>>(LinkEntityExtensions.GetSubtree)))
			{
				yield return current;
			}
			yield break;
		}
	}
}
